Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add experimental AwsTerraformAdapter to support interoperability with AWS CDK constructs #1123

Closed
wants to merge 40 commits into from

Conversation

ansgarm
Copy link
Member

@ansgarm ansgarm commented Oct 5, 2021

NOTE: The adapter did move to its own package (and repository): https://github.com/hashicorp/cdktf-aws-cdk
Progress (see tasks below) will still be tracked in this PR.


This PR adds an experimental adapter which can be used to deploy AWS CDK (v2) constructs using CDK for Terraform.
It uses the new Cloud Control API (specifically the awscc Terraform provider) to provision resources using Terraform.

⚠️ This is an early preview ⚠️

The branch is based on the support-nested-type branch (PR) as the awscc provider makes use of those new types.

For resources that are not yet available in the Cloud Control API (e.g. IAM resources) a custom mapping can be supplied instead. We plan to include some of these mappings already but cannot guarantee completeness.

Resolves #244, Relates to #474

local development instructions The `aws-adapter` package currently depends on `@cdktf/provider-aws` which in turn depends on `cdktf=^0.6` which blocks us from testing local changes to the `cdktf` package (because JSII is very strict about versions and the work in progress version is of the `cdktf` is `0.0.0`. Hence some extensive linking is required:
# in cdktf
> yarn install
> yarn build
> yarn package
> yalc publish cdktf


# aws provider
> gco cdktf-provider-aws
> yarn install
> yarn build
> yalc link cdktf
# edit package.json `"cdktf": "0.0.0",` in dependencies and peerDependencies
> yarn jsii --silence-warnings=reserved-word --no-fix-peer-dependencies
> yalc publish

# in aws-adapter
> yalc link @cdktf/provider-aws

# in terraform cdk
> yarn build
> yarn package

Open tasks

  • Migrate PoC code to terraform-cdk repo
  • Add @cdktf/aws-adapter package
  • Autobind Cloud Control API supported resources to awscc provider resources
  • Support intrinsic functions (e.g. Fn::Sub)
  • Fix propertyAccess / markAsInner for Refs (see test case for Fn::FindInMap)
  • Support Conditions (example, example 2)
  • Find a way to use @cdktf/aws-adapter with [email protected] without JSII failing
  • ^ move into separate repository (cdktf-aws-cdk) and rename package to @cdktf/aws-cdk
  • ^ generate module bindings for aws adapter in that repo and ship it alongside the repo
  • ^ base the separate repo on cdktf-provider-aws (4hr cron for updates, JSII config, etc.)
  • Explore simplifying mappings by using aws_cloudcontrolapi_resource instead of individual resources (we don't have to convert the attribute names this way)
  • Support Outputs property of Cfn template
  • Build workaround for eventual consistency issue with IAM resources
  • Add unit tests for new functionality added to tfExpression.ts
  • Add some more examples using common AWS CDK packages
  • Write docs for using the AwsTerraformAdapter
  • Add section to docs about how the adapter works internally
  • Docs: AWS Stack and App are not supported
  • Add link to docs where to find aws cc supported resources (link)
  • Add section to docs about things on the roadmap which currently don't work
  • Make sure the docs find their way into the new docs
  • Support passing Tokens between constructs (This needs work on the Token system and might be deferred due to complexity, we should offer at least a basic way!)
  • Make sure each example has an snapshot test

Follow-up tasks

(to be tracked as separate issues)

Deferred to later iterations

ansgarm added 30 commits October 5, 2021 11:06
re-uses the existing interface of a post processor to be able to apply changes to a lazy value after it resolved lazily. This functionality is then used for marking and TFExpression as an inner one to be able to reference attributes of mapped resources correctly in the resulting Terraform config
Copy link
Collaborator

@jsteinich jsteinich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to mostly just be work that's also in other PRs. How much of what is here is actually unique / used anymore?

@@ -84,6 +84,7 @@
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"constructs": "^10.0.0",
"aws-cdk-lib": "2.0.0-rc.23",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway to not take a hard dependency here?

@@ -22,7 +22,7 @@ export class TerraformDataSource
// TerraformMetaArguments

public dependsOn?: string[];
public count?: number;
public count?: number | IResolvable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was already merged in a different PR, but ultimately keeping as a number would be ideal.

description?: string;
required?: boolean;
optional?: boolean;
computed?: boolean;
sensitive?: boolean;
}

interface NestedTypeAttribute extends BaseAttribute {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to merge the other PR, or just include in this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out that the other PR was not needed for this to work as we now use the aws_cloudcontrolapi_resource instead of the awscc provider. Also: the adapter code moved to https://github.com/hashicorp/cdktf-aws-cdk
So this PR only serves as a checklist and will be closed soon.

}

private emitToTerraformFuction(struct: Struct) {
this.code.line();
this.code.openBlock(
`function ${downcaseFirst(struct.name)}ToTerraform(struct?: ${
`export function ${downcaseFirst(struct.name)}ToTerraform(struct?: ${
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this add a bunch of jsii warning?

// are exported for now. We might want to improve the control flow
// here in way to determine which structs need really this function
// and which don't.
// TODO: only do this if the parent of this struct needs it to be exported because any parent might expose it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just structs belonging to nested types that need this?

@ansgarm
Copy link
Member Author

ansgarm commented Oct 22, 2021

As described in the PR description: The adapter moved to a separate repo and hence this PR will never be merged, as the code lives here now: hashicorp/cdktf-aws-cdk.

I created follow-up issues for all remaining tasks that did not make it into the initial increment.

Closing this 👋

@ansgarm ansgarm closed this Oct 22, 2021
@ansgarm ansgarm deleted the experimental-aws-adapter branch October 22, 2021 11:29
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature/aws-adapter [experimental] Deploy AWS CDK constructs using CDKTF provider/aws Issue shows up using AWS provider providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compatibility with aws-cdk
2 participants